<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" th:href="@{res/css/amazeui.min.css}">
    <link rel="stylesheet" th:href="@{res/css/admin.css}">
    <script th:src="@{/js/jquery-1.11.3.min.js}"></script>
    <script th:src="@{/myplugs/js/plugs.js}"></script>

    <style>
        .admin-main{
            padding-top: 0px;
        }
        #cancel{
            margin-left: 20%;
        }
    </style>
</head>
<body>
<div class="am-cf admin-main">
    <!-- content start -->
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-g">
                <div class="am-form am-form-horizontal"
                     style="padding-top:30px;">
                    <div class="am-form-group">
                        <label for="menuName" class="am-u-sm-3 am-form-label">
                            菜单名称: </label>
                        <div class="am-u-sm-9">
                            <input type="text" id="menuName"
                                   name="menuName">
                        </div>
                    </div>
                    <div class="am-form-group">
                        <label for="menuName" class="am-u-sm-3 am-form-label">
                            URL: </label>
                        <div class="am-u-sm-9">
                            <input type="text" id="menuUrl"
                                   name="menuName">
                        </div>
                    </div>
                    <div class="am-form-group">
                        <label for="belongTo" class="am-u-sm-3 am-form-label">
                            隶&nbsp;&nbsp;属&nbsp;&nbsp;方:</label>
                        <div class="am-u-sm-9">
                            <select id="belongTo">
                                <option value="1">品牌商</option>
                                <option value="2">借卖方</option>
                                <option value="3">管理员</option>
                            </select>
                        </div>
                    </div>
                    <div class="am-form-group">
                        <div class="am-u-sm-9 am-u-sm-push-3">
                            <input type="button" class="am-btn am-btn-primary" value="确认" id="confirm"/>
                            <input type="button" class="am-btn am-btn-primary" value="取消" id="cancel"/>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

<script>
$(function(){
    $("#confirm").click(function(){

        var name = $("#menuName").val();
        var url = $("#menuUrl").val();
        var belongTo = $("#belongTo").val();
        var menu_id;
        var level = 0;
        if(belongTo == 1)
            menu_id = 1;
        else if(belongTo == 2)
            menu_id = 6;
        else
            menu_id = 12;

        $.ajax({
            type:"post",
            url:"/menu/addMenu",
            dataType:"text",
            data:{name:name,menu_id:menu_id,level:level,url:url},
            success:function(result){
                alert(result);
                parent.parent.location.reload();
            },
            error:function (result) {
                alert(result);
            }
        })

    })


    $("#cancel").click(function(){
        parent.parent.location.reload();
    })
})

</script>
</html>